package com.goods.controller.business;


import com.goods.common.model.business.Health;
import com.goods.common.response.ResponseBean;
import com.goods.common.utils.ListPageUtils;
import com.goods.common.vo.business.HealthVO;
import com.goods.service.HealthService;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/business/health")
public class HealthController {

    @Autowired
    HealthService healthService;

    @GetMapping("/isReport")
    public ResponseBean isReport(){
        Health health = healthService.isReport();

        if (health == null){
            return ResponseBean.success();
        }else {
            HealthVO healthVO = new HealthVO();
            BeanUtils.copyProperties(health,healthVO);
            return ResponseBean.success(healthVO);
        }
    }

    @PostMapping("/report")
    public ResponseBean report(@RequestBody HealthVO healthVO){
        int i = healthService.report(healthVO);
        if (i == 0 ){
            return ResponseBean.error("打卡失败");
        }else {
            return ResponseBean.success();
        }
    }

    @GetMapping("/history")
    public ResponseBean history(Integer pageSize,Integer pageNum){
        Map map = new HashMap();
        List<Health> list = healthService.history();
        List<Health> page = ListPageUtils.page(list, pageSize, pageNum);
        map.put("rows",page);
        map.put("total",list.size());
        return ResponseBean.success(map);
    }
}
